//
//  BDGoodDetailViewController.m
//  BeidouMall
//
//  Created by qie on 16/5/12.
//  Copyright © 2016年 qie. All rights reserved.
//

#import "BDGoodDetailViewController.h"
#import "SDCycleScrollView.h"
#import "BDNavigationBarView.h"
#import "BDNavGoodDetailHeader.h"
#import "BDGoodDetailFirestTableViewCell.h"
#import "StandardsView.h"
#import "BDNavigationController.h"
#import "BDBeidouPayViewController.h"
#import "BDPaySuccessViewController.h"

#define kPageSize 5
#define firstHeightWidthRatio 1.256

@interface BDGoodDetailViewController () <SDCycleScrollViewDelegate,BDNavGoodDetailHeaderDelegate,StandardsViewDelegate,SimplePopupViewDelegate>
{
    NSInteger _curPage;
    NSArray *_topList;// 顶部滑动图片
    NSArray *_detailList;// 商品详情图片
    NSMutableArray *_commentsList;// 商品评论
    NSDictionary *_commodityDic;// 商品详情
    BDNavGoodDetailHeader *_navView;
    CGRect _defaultTopViewRect;// 控制顶部滑动图片缩放
    int _page;// 商品或详情
    
    BOOL _toCartFlag;// 点击加入购物车按钮标记
    StandardsView *_standview;// 加入购物车或立即购买底部弹出视图
    SDCycleScrollView *_cycleScrollView;// 顶部滑动图片控件
    BOOL _showTop;// 是否马上显示返回顶部
    
    UIButton *_topButton;// 返回顶部按钮
    SimplePopupView *_popView;
}
@property (weak, nonatomic) IBOutlet NSLayoutConstraint *viewWidth;// 三个屏幕的宽度
@property (weak, nonatomic) IBOutlet NSLayoutConstraint *secondViewLeading;// 第二个tableView起始位置
@property (weak, nonatomic) IBOutlet NSLayoutConstraint *secondTableViewWidth;

@property (weak, nonatomic) IBOutlet UITableView *tableView;
@property (weak, nonatomic) IBOutlet UITableView *secondTableView;
@property (weak, nonatomic) IBOutlet UITableView *thirdTableView;
@property (weak, nonatomic) IBOutlet UIView *containerView;// 顶部滑动图片视图
@property (weak, nonatomic) IBOutlet UIScrollView *containerScrollView;// 整体滑动视图
@property (weak, nonatomic) IBOutlet UIView *bottomView;// 底部视图(加入购物车和立即购买)
@property (weak, nonatomic) IBOutlet UILabel *promitLabel;
@property (weak, nonatomic) IBOutlet UIButton *addBeidouButton;
@property (weak, nonatomic) IBOutlet UIButton *payButton;
@property (weak, nonatomic) IBOutlet NSLayoutConstraint *bottomViewHeightConstraint;// 这三个控制是否提示进入了便民商品但不能购买的情况
@property (weak, nonatomic) IBOutlet NSLayoutConstraint *addBeidouButtonTopConstraint;
@property (weak, nonatomic) IBOutlet NSLayoutConstraint *payButtonTopConstraint;


@end

@implementation BDGoodDetailViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    _commentsList = [NSMutableArray array];
    // 获取商品顶部,商品数据,详情图片
    [self reloadData:nil];
    // 添加顶部图片视图
    [self loadTopView];
    // 尾部获取评论,但是还是需要调用[_tableView.mj_footer beginRefreshing]
    _thirdTableView.mj_footer = [MJDIYBackFooter footerWithRefreshingBlock:^{
        [self reloadComments:nil];
    }];
    [_thirdTableView.mj_footer beginRefreshing];
    // 添加返回顶部按钮
    _topButton = [UIButton buttonWithType:UIButtonTypeCustom];
    _topButton.frame = CGRectMake(kScreen_Width - 45.0, kScreen_Height, 40.0, 40.0);
    [_topButton setImage:[UIImage imageNamed:@"toTop"] forState:UIControlStateNormal];
    [_topButton addTarget:self action:@selector(scrollViewTop:) forControlEvents:UIControlEventTouchUpInside];
    [self.view addSubview:_topButton];
    [self.view bringSubviewToFront:self.bottomView];
    
    _curPage = 0;
    [self setHeaderPopView];
}

- (void)viewWillAppear:(BOOL)animated {
    [super viewWillAppear:animated];
    // 添加导航栏
    _navView = [[NSBundle mainBundle] loadNibNamed:@"BDNavGoodDetailHeader" owner:nil options:nil].firstObject;
    _navView.frame = CGRectMake(0.0, 0.0, kScreen_Width, 64.0);
    _navView.delegate = self;
    _navView.goodLabel.text = NSLocalizedString(@"Commodity", nil);
    _navView.detailLabel.text = NSLocalizedString(@"Details", nil);
    _navView.commentLabel.text = NSLocalizedString(@"Comments", nil);
    if ([[BDAccountManagerModel shareInstance].langage isEqualToString:@"zang"]) {
        _navView.goodLabel.font = [UIFont fontWithName:@"BZDHT" size:9.0];
        _navView.detailLabel.font = [UIFont fontWithName:@"BZDHT" size:9.0];
        _navView.commentLabel.font = [UIFont fontWithName:@"BZDHT" size:9.0];
    }
    [self.navigationController.view addSubview:_navView];
    
    if (_page == 1) {// 从立即购买返回时,如果停留在详情栏则应该返回时依旧停留在详情栏
        [self detailMethod];
    }
    
    // 从立即购买返回时,返回顶部应该依旧显示
    _topButton.y = _showTop ? kScreen_Height - 95.0 : kScreen_Height;
    if (self.notCustomNavigatonBar) {
        _topButton.y -= 64.0;
    }
    
    // 麻烦的跳转
    if ([[BDAccountManagerModel shareInstance].payResult isEqualToString:@"success"] ||
        [[BDAccountManagerModel shareInstance].payResult isEqualToString:@"fail"]) {// 支付成功或失败
        
        UIStoryboard *stroyboard = [UIStoryboard storyboardWithName:@"Main" bundle:[NSBundle mainBundle]];
        BDNavigationController *nav_payVc = [stroyboard instantiateViewControllerWithIdentifier:@"PaySuccessStroyboardID"];
        BDPaySuccessViewController *payVc = (BDPaySuccessViewController *)nav_payVc.topViewController;
        payVc.type = [BDAccountManagerModel shareInstance].payResult;
        [self presentViewController:nav_payVc animated:YES completion:nil];
        
    } else if ([[BDAccountManagerModel shareInstance].payResult isEqualToString:@"popToRoot"]) {// 退到根节点
        [BDAccountManagerModel shareInstance].payResult = @"selectTabBar";
        [self.navigationController popToRootViewControllerAnimated:YES];
    }
    
}

- (void)viewWillDisappear:(BOOL)animated {
    [super viewWillDisappear:animated];
    [_navView removeFromSuperview];
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

//更新约束
- (void)updateViewConstraints {
    [super updateViewConstraints];
    //设置为三个屏幕的宽度
    self.viewWidth.constant = CGRectGetWidth([UIScreen mainScreen].bounds) * 3;
    self.secondViewLeading.constant = CGRectGetWidth([UIScreen mainScreen].bounds);
    self.secondTableViewWidth.constant = CGRectGetWidth([UIScreen mainScreen].bounds);
}

#pragma mark - Private method

- (void)reloadData:(id) sender {
    // 获取商品详情
    MBProgressHUD *hud = [MBProgressHUD showHUDAddedTo:self.navigationController.view withText:@""];
    NSString *url1 = [NSString stringWithFormat:@"%@%@?commodityId=%@",
                     [BDNetworking shareInstance].baseUrl,
                     Good_DetailQuery,
                     self.commodityId];
    [[BDNetworking shareInstance] postWithUrl:url1 sid:nil method:@"GET" parameters:nil completionHandler:^(NSObject *results, NSError *error) {
        [hud hideAfterDelay:0.5];
        if (error != nil) {
            NSLog(@"商品详情获取失败:%@",error);
            [MBProgressHUD showToast:self.view withText:NSLocalizedString(@"Fail to get commodity details info", nil)];
        } else {
            NSLog(@"result = %@",results);
            if ([results isKindOfClass:[NSDictionary class]]) {
                _commodityDic = (NSDictionary *)results;
                dispatch_async(dispatch_get_main_queue(), ^{// 一般状态
                    self.promitLabel.hidden = YES;
                    self.bottomViewHeightConstraint.constant = 40.0;
                    self.addBeidouButtonTopConstraint.constant = 0.0;
                    self.payButtonTopConstraint.constant = 0.0;
                    self.payButton.enabled = YES;
                    self.addBeidouButton.enabled = YES;
                });
                
                dispatch_async(dispatch_get_main_queue(), ^{
                    [self.tableView reloadData];
                });
                [self setPromitInfo];
            }
        }
    }];
    // 获取顶部图片
    NSString *url2 = [NSString stringWithFormat:@"%@%@?commodityId=%@&type=TOP_PIC",
                     [BDNetworking shareInstance].baseUrl,
                     Good_DetailPicQuery,
                     self.commodityId];
    [[BDNetworking shareInstance] postWithUrl:url2 sid:nil method:@"GET" parameters:nil completionHandler:^(NSObject *results, NSError *error) {
        if (error != nil) {
            NSLog(@"商品详情顶部图片获取失败:%@",error);
            [MBProgressHUD showToast:self.view withText:NSLocalizedString(@"Fail to get commodity details info", nil)];
        } else {
            NSLog(@"result = %@",results);
            if ([results isKindOfClass:[NSArray class]]) {
                _topList = (NSArray *)results;
                dispatch_async(dispatch_get_main_queue(), ^{
                    SDCycleScrollView *cycleScrollView = (SDCycleScrollView *)[self.containerView viewWithTag:101];
                    NSMutableArray *imagesURLStrings = [NSMutableArray array];
                    for (NSDictionary *goodDic in _topList) {
                        NSString *picUrl = goodDic[@"picUrl"];
                        if (![picUrl isEqual:[NSNull null]] &&
                            picUrl != nil) {
                            [imagesURLStrings addObject:picUrl];
                        }
                    }
                    cycleScrollView.imageURLStringsGroup = imagesURLStrings;
                    cycleScrollView.autoScrollTimeInterval = 3.0;
                });
            }
        }
    }];
    // 获取商品详情图片
    NSString *url3 = [NSString stringWithFormat:@"%@%@?commodityId=%@&type=DETAIL_PIC",
                      [BDNetworking shareInstance].baseUrl,
                      Good_DetailPicQuery,
                      self.commodityId];
    [[BDNetworking shareInstance] postWithUrl:url3 sid:nil method:@"GET" parameters:nil completionHandler:^(NSObject *results, NSError *error) {
        if (error != nil) {
            NSLog(@"商品详情图片获取失败:%@",error);
            [MBProgressHUD showToast:self.view withText:NSLocalizedString(@"Fail to get commodity details info", nil)];
        } else {
            NSLog(@"result = %@",results);
            if ([results isKindOfClass:[NSArray class]]) {
                _detailList = (NSArray *)results;
                dispatch_async(dispatch_get_main_queue(), ^{
                    [_secondTableView reloadData];
                });
            }
        }
    }];
}

- (void)reloadComments:(id) sender {
    _curPage = sender == self ? 1 : _curPage + 1;
    // 获取商品评论
    NSString *url = [NSString stringWithFormat:@"%@%@?currentPage=%ld&pageSize=%d&commodityId=%@",
                      [BDNetworking shareInstance].baseUrl,
                      Good_Comments,
                      (long)_curPage,
                      kPageSize,
                      self.commodityId];
    [[BDNetworking shareInstance] postWithUrl:url sid:nil method:@"GET" parameters:nil completionHandler:^(NSObject *results, NSError *error) {
        dispatch_async(dispatch_get_main_queue(), ^{
            if ([_thirdTableView.mj_footer isRefreshing]) {
                [_thirdTableView.mj_footer endRefreshing];
            }
        });
        if (error != nil) {
            NSLog(@"商品详情评论获取失败:%@",error);
            [MBProgressHUD showToast:self.view withText:NSLocalizedString(@"Fail to get commodity comments", nil)];
        } else {
            if ([results isKindOfClass:[NSDictionary class]]) {
                NSLog(@"results = %@",results);
                NSDictionary *resultDic = (NSDictionary *)results;
                NSArray *resultList = resultDic[@"objects"];
                if ([resultList count] > 0) {
                    if ([resultList count] < kPageSize) {// 数据不够分页,显示没有更多了
                        dispatch_async(dispatch_get_main_queue(), ^{
                            [_thirdTableView.mj_footer endRefreshingWithNoMoreData];
                        });
                    }
                    if (sender == self) {
                        [_commentsList removeAllObjects];
                    }
                    [_commentsList addObjectsFromArray:resultList];
                } else {
                    if (_curPage > 1) { // 分页引起的刷新
                        dispatch_async(dispatch_get_main_queue(), ^{
                            [_thirdTableView.mj_footer endRefreshingWithNoMoreData];
                        });
                    } else { // 第一次数据就为空
                        dispatch_async(dispatch_get_main_queue(), ^{
                            _thirdTableView.mj_footer.hidden = YES;
                        });
                        [_commentsList removeAllObjects];
                    }
                }
                dispatch_async(dispatch_get_main_queue(), ^{
                    [_thirdTableView reloadData];
                    [_tableView reloadData];
                    if (_curPage == 1) {// 自定义的尾部
                        _thirdTableView.contentOffset = CGPointZero;
                    }
                });
            }
        }
    }];
}

- (void)loadTopView {// 顶部图片
    dispatch_async(dispatch_get_main_queue(), ^{
        NSMutableArray *imagesURLStrings = [NSMutableArray array];
        _cycleScrollView = [SDCycleScrollView cycleScrollViewWithFrame:CGRectMake(0, 0, kScreen_Width, kScreen_Width / firstHeightWidthRatio) delegate:self placeholderImage:[UIImage imageNamed:@"placeholder"]];
        _cycleScrollView.autoScroll = NO;
        _cycleScrollView.pageControlAliment = SDCycleScrollViewPageContolAlimentCenter;
        _cycleScrollView.currentPageDotColor = [UIColor orangeColor]; // 自定义分页控件小圆标颜色
        _cycleScrollView.pageDotColor = RGBColor(210, 210, 210);
        _cycleScrollView.imageURLStringsGroup = imagesURLStrings;
        _cycleScrollView.tag = 101;
        _cycleScrollView.backgroundColor = RGBColor(229, 229, 229);
        _defaultTopViewRect = _cycleScrollView.frame;
        [self.containerView addSubview:_cycleScrollView];
        [self.containerView sendSubviewToBack:_cycleScrollView];
    });
}

- (void)scrollViewTop:(UIButton *)sender {
    if (_page == 0) {
        [self.tableView setContentOffset:CGPointMake(0, 0) animated:YES];
    } else if (_page == 1) {
        [self.secondTableView setContentOffset:CGPointMake(0, 0) animated:YES];
    } else if (_page == 2) {
        [self.thirdTableView setContentOffset:CGPointMake(0, 0) animated:YES];
    }
}

- (void)setHeaderPopView {
    NSArray *tmpArray = @[NSLocalizedString(@"home", nil),NSLocalizedString(@"message", nil)];
    NSArray *images = @[@"homeback",@"messageback"];
    //左
    _popView = [[SimplePopupView alloc] initWithFrame:CGRectMake(kScreen_Width - 130.0, 55.0, 120.0, 80.0)
                                         andDirection:PopViewDirectionTop
                                            andTitles:tmpArray
                                            andImages:images
                                       trianglePecent:0.5]; //箭头位于popview中间0.5位置
    [self.navigationController.navigationBar showPopView:_popView AtPoint:CGPointMake(0.5, 0)];//箭头位于button的x=0.y=0.5比例处
    _popView.delegate = self; //需要正式使用时注意代理
}

- (void)setPromitInfo {// 1、不在康定 2、下架了 3、库存为0
    NSDictionary *classify = _commodityDic[@"classify"];
    NSString *status = _commodityDic[@"status"];// 商品状态(判断是否下架)
    NSString *num = _commodityDic[@"num"];// 商品库存
    // 判断是否是便民商品
    if (![classify isEqual:[NSNull null]] &&
        [classify isKindOfClass:[NSDictionary class]]) {
        NSString *firstLevel = classify[@"firstLevel"];
        if (![firstLevel isEqual:[NSNull null]]) {
            if ([firstLevel isEqualToString:@"conveniency"] &&
                [[BDAccountManagerModel shareInstance].inBoundary isEqualToString:@"no"]) {//便民商品且不在指定地区
                dispatch_async(dispatch_get_main_queue(), ^{
                    self.promitLabel.hidden = NO;
                    self.bottomViewHeightConstraint.constant = 56.0;
                    self.addBeidouButtonTopConstraint.constant = 16.0;
                    self.payButtonTopConstraint.constant = 16.0;
                    self.payButton.enabled = NO;
                    self.addBeidouButton.enabled = NO;
                    if ([[BDAccountManagerModel shareInstance].langage isEqualToString:@"zang"]) {
                        self.promitLabel.font = [UIFont fontWithName:@"Bzdbt" size:7.0];
                    }
                });
                return;
            }
        }
    }
    // 判断商品是否下架
    if (![status isEqual:[NSNull null]]) {
        if ([status isEqualToString:@"ONSELL"]) {
            
        }
    } else {
        dispatch_async(dispatch_get_main_queue(), ^{
            self.promitLabel.hidden = NO;
            self.promitLabel.text = NSLocalizedString(@"The goods have been off the shelf", nil);
            self.bottomViewHeightConstraint.constant = 56.0;
            self.addBeidouButtonTopConstraint.constant = 16.0;
            self.payButtonTopConstraint.constant = 16.0;
            self.payButton.enabled = NO;
            self.addBeidouButton.enabled = NO;
            if ([[BDAccountManagerModel shareInstance].langage isEqualToString:@"zang"]) {
                self.promitLabel.font = [UIFont fontWithName:@"Bzdbt" size:7.0];
            }
        });
        return;
    }
    // 判断库存是否为空
    if (![num isEqual:[NSNull null]]) {
        NSInteger goodNum = [num integerValue];
        if (goodNum <= 0) {
            dispatch_async(dispatch_get_main_queue(), ^{
                self.promitLabel.hidden = NO;
                self.promitLabel.text = NSLocalizedString(@"The goods have been sold out", nil);
                self.bottomViewHeightConstraint.constant = 56.0;
                self.addBeidouButtonTopConstraint.constant = 16.0;
                self.payButtonTopConstraint.constant = 16.0;
                self.payButton.enabled = NO;
                self.addBeidouButton.enabled = NO;
                if ([[BDAccountManagerModel shareInstance].langage isEqualToString:@"zang"]) {
                    self.promitLabel.font = [UIFont fontWithName:@"Bzdbt" size:7.0];
                }
            });
            return;
        }
    }
}

#pragma mark SimplePopupView delegate

- (void)simplePopupView:(SimplePopupView *)popView clickAtIndexPath:(NSIndexPath *)indexPath {
    NSLog(@"代理方法，点击了第%ld行",(long)indexPath.row);
    if (indexPath.row == 0) {
        self.tabBarController.selectedIndex = 0;
        dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(0.1 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
            [self.navigationController popToRootViewControllerAnimated:YES];
        });
    } else if (indexPath.row == 1) {
        [MBProgressHUD showToast:self.view withText:NSLocalizedString(@"Still in process", nil)];
    }
}

#pragma mark BDNavGoodDetailHeaderDelegate

- (void)backMethod {
    [self.navigationController popViewControllerAnimated:YES];
}

- (void)goodMethod {
    _page = 0;
    // 返回顶部按钮是否显示
    CGFloat offsetY = self.tableView.contentOffset.y;
    if (offsetY > 100) {
        _topButton.y = kScreen_Height - 95.0;
        if (self.notCustomNavigatonBar) {
            _topButton.y -= 64.0;
        }
    }
    if (offsetY < 100){
         _topButton.y = kScreen_Height;
        if (self.notCustomNavigatonBar) {
            _topButton.y -= 64.0;
        }
    }
    // 到商品的滑动动画
    if (_navView.line.center.x != _navView.goodLabel.center.x) {
        _navView.goodLabel.textColor = RGBColor(215, 19, 33);
        _navView.detailLabel.textColor = RGBColor(102, 102, 102);
        _navView.commentLabel.textColor = RGBColor(102, 102, 102);
        [UIView beginAnimations:@"move" context:nil];
        _navView.line.center = _navView.goodLabel.center;
        _navView.line.y = CGRectGetMaxY(_navView.frame) - 3;
        [UIView commitAnimations];
    }
    if (self.containerScrollView.contentOffset.x != 0) {
        [UIView beginAnimations:@"scroller" context:nil];
        self.containerScrollView.contentOffset = CGPointZero;
        [UIView commitAnimations];
    }
}

- (void)detailMethod {
    _page = 1;
    // 返回顶部按钮是否显示
    CGFloat offsetY = self.secondTableView.contentOffset.y;
    if (offsetY > 100) {
        _topButton.y = kScreen_Height - 95.0;
        if (self.notCustomNavigatonBar) {
            _topButton.y -= 64.0;
        }
    }
    if (offsetY < 100){
        _topButton.y = kScreen_Height;
        if (self.notCustomNavigatonBar) {
            _topButton.y -= 64.0;
        }
    }
    // 到详情的滑动动画
    [self.secondTableView reloadData];// 不知道会出什么问题，原来是注释掉了
    if (_navView.line.center.x != _navView.detailLabel.center.x) {
        _navView.goodLabel.textColor = RGBColor(102, 102, 102);
        _navView.detailLabel.textColor = RGBColor(215, 19, 33);
        _navView.commentLabel.textColor = RGBColor(102, 102, 102);
        [UIView beginAnimations:@"move" context:nil];
        _navView.line.center = _navView.detailLabel.center;
        _navView.line.y = CGRectGetMaxY(_navView.frame) - 3;
        [UIView commitAnimations];
    }
    if (self.containerScrollView.contentOffset.x != kScreen_Width) {
        [UIView beginAnimations:@"scroller" context:nil];
        self.containerScrollView.contentOffset = CGPointMake(kScreen_Width, 0);
        [UIView commitAnimations];
    }
}

- (void)commentMethod {
    _page = 2;
    // 返回顶部按钮是否显示
    CGFloat offsetY = self.secondTableView.contentOffset.y;
    if (offsetY > 100) {
        _topButton.y = kScreen_Height - 95.0;
        if (self.notCustomNavigatonBar) {
            _topButton.y -= 64.0;
        }
    }
    if (offsetY < 100){
        _topButton.y = kScreen_Height;
        if (self.notCustomNavigatonBar) {
            _topButton.y -= 64.0;
        }
    }
    // 到详情的滑动动画
    [self.thirdTableView reloadData];// 不知道会出什么问题，原来是注释掉了
    if (_navView.line.center.x != _navView.commentLabel.center.x) {
        _navView.goodLabel.textColor = RGBColor(102, 102, 102);
        _navView.detailLabel.textColor =  RGBColor(102, 102, 102);
        _navView.commentLabel.textColor = RGBColor(215, 19, 33);
        [UIView beginAnimations:@"move" context:nil];
        _navView.line.center = _navView.commentLabel.center;
        _navView.line.y = CGRectGetMaxY(_navView.frame) - 3;
        [UIView commitAnimations];
    }
    if (self.containerScrollView.contentOffset.x != kScreen_Width * 2) {
        [UIView beginAnimations:@"scroller" context:nil];
        self.containerScrollView.contentOffset = CGPointMake(kScreen_Width * 2, 0);
        [UIView commitAnimations];
    }
}

- (void)homeMethod {
    [_popView show:CGRectMake(kScreen_Width - 130.0, 55.0, 120.0, 80.0)];
}

#pragma mark tableView dataSrouce

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
    if (tableView == _tableView) {
//        return _commentsList.count > 0 ? _commentsList.count + 3 : 4;
        if (_commentsList.count == 0) {
            return 4;
        } else if (_commentsList.count == 1) {
            return 4;
        } else if (_commentsList.count == 2) {
            return 5;
        } else if (_commentsList.count == 3) {
            return 6;
        } else if (_commentsList.count > 3) {
            return 7;
        }  else {
            return 7;
        }
//        return _commentsList.count > 0 ? 5 : 4;
    } else if (tableView == _secondTableView) {
        return 2;
    } else {
        return _commentsList.count > 0 ? _commentsList.count : 1;
    }
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    if (tableView == _tableView) {
        if (indexPath.row == 0) {
            static NSString *cellStr = @"goodImgCell";
            UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:cellStr];
            
            return cell;
        } else if (indexPath.row == 1) {
            static NSString *cellStr = @"goodDescCell";
            BDGoodDetailFirestTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:cellStr];
            // 商品名称
            UILabel *nameLabel = [(UILabel *)cell viewWithTag:101];
            NSString *goodName = _commodityDic[@"name"];
            if (![goodName isEqual:[NSNull null]]) {
                nameLabel.text = goodName;
            }
            // 星级评分
            UIView *containerView = [cell viewWithTag:102];
            NSString *levelStr = _commodityDic[@"level"];
            if (![levelStr isEqual:[NSNull null]]) {
                NSInteger level = [levelStr integerValue];
                switch (level) {
                    case 1:
                        [containerView viewWithTag:203].hidden = NO;
                        cell.containerViewAlignCenter.constant = 4.0;
                        break;
                    case 2:
                        [containerView viewWithTag:202].hidden = NO;
                        [containerView viewWithTag:203].hidden = NO;
                        cell.containerViewAlignCenter.constant = 12.0;
                        break;
                    case 3:
                        [containerView viewWithTag:202].hidden = NO;
                        [containerView viewWithTag:203].hidden = NO;
                        [containerView viewWithTag:204].hidden = NO;
                        cell.containerViewAlignCenter.constant = 4.0;
                        break;
                    case 4:
                        [containerView viewWithTag:202].hidden = NO;
                        [containerView viewWithTag:203].hidden = NO;
                        [containerView viewWithTag:204].hidden = NO;
                        [containerView viewWithTag:205].hidden = NO;
                        cell.containerViewAlignCenter.constant = -5.0;
                        break;
                    case 5:
                        [containerView viewWithTag:201].hidden = NO;
                        [containerView viewWithTag:202].hidden = NO;
                        [containerView viewWithTag:203].hidden = NO;
                        [containerView viewWithTag:204].hidden = NO;
                        [containerView viewWithTag:205].hidden = NO;
                        cell.containerViewAlignCenter.constant = 0.0;
                        break;
                    default:
                        break;
                }
            }
            // 商品折扣价格
            UILabel *goodDiscountLabel = (UILabel *)[cell viewWithTag:103];
            // 商品价格
            UILabel *goodPriceLabel = (UILabel *)[cell viewWithTag:104];
            // 价格label
            UILabel *goodPricePromitLable = (UILabel *)[cell viewWithTag:109];
            goodPricePromitLable.text = NSLocalizedString(@"DetailPrice", nil);
            
            NSString *goodDiscount = _commodityDic[@"commodityPrice"][@"discount"];
            NSString *goodPrice = _commodityDic[@"commodityPrice"][@"price"];
            if (![goodDiscount isEqual:[NSNull null]] &&
                ![goodPrice isEqual:[NSNull null]]) {
                // 折扣价格
                CGFloat discount = [goodDiscount floatValue];
                CGFloat price = [goodPrice floatValue];
                goodDiscountLabel.text = [NSString stringWithFormat:@"¥ %.2f",price * discount];
                // 价格
                NSString *str = [NSString stringWithFormat:@"¥ %.2f",[goodPrice floatValue]];
                NSDictionary *attribtDic = @{NSStrikethroughStyleAttributeName: [NSNumber numberWithInteger:NSUnderlineStyleSingle]};
                NSMutableAttributedString *attribtStr = [[NSMutableAttributedString alloc] initWithString:str attributes:attribtDic];
                goodPriceLabel.attributedText = attribtStr;
                if (discount >= 1.0 || [goodPriceLabel.text isEqualToString:goodDiscountLabel.text]) {
                    goodPriceLabel.hidden = YES;
                } else {
                    goodPriceLabel.hidden = NO;
                }
            }
            // 商品销量
            UILabel *goodNumLabel = [(UILabel *)cell viewWithTag:105];
            NSString *goodNum = _commodityDic[@"saleNum"];
            if (![goodNum isEqual:[NSNull null]]) {
                goodNumLabel.text = [NSString stringWithFormat:@"%@%ld",NSLocalizedString(@"Sales", nil),(long)[goodNum integerValue]];
                if ([[BDAccountManagerModel shareInstance].langage isEqualToString:@"zh"]) {
                    goodNumLabel.text = [NSString stringWithFormat:@"%@%ld笔",@"销量",(long)[goodNum integerValue]];
                }
                if ([[BDAccountManagerModel shareInstance].langage isEqualToString:@"zang"]) {
                    goodNumLabel.text = [NSString stringWithFormat:@"%@%ld",@"销量：",(long)[goodNum integerValue]];
                }
            }
            // 店铺地址
            UILabel *goodAddressLabel = [(UILabel *)cell viewWithTag:106];
            NSString *goodAddress = _commodityDic[@"store"][@"address"];
            if (![goodAddress isEqual:[NSNull null]]) {
                goodAddressLabel.text = [NSString stringWithFormat:@"产地：%@",goodAddress];
            }
            // 物流运费
            UILabel *goodExpressLabel = [(UILabel *)cell viewWithTag:107];
            goodExpressLabel.text = NSLocalizedString(@"Third party Express fees", nil);
            NSArray *expressList = _commodityDic[@"commodityExpress"];
            if (![expressList isEqual:[NSNull null]] &&
                expressList.count > 0) {
                NSDictionary *classify = _commodityDic[@"classify"];
                if (![classify isEqual:[NSNull null]] &&
                    [classify isKindOfClass:[NSDictionary class]]) {
                    NSString *firstLevel = classify[@"firstLevel"];
                    if (![firstLevel isEqual:[NSNull null]]) {
                        if ([firstLevel isEqualToString:@"conveniency"]) {//便民商品
//                            goodExpressLabel.text = NSLocalizedString(@"Beidou Express fees", nil);
                            for (NSDictionary *dic in expressList) {
                                NSString *expressType = dic[@"expressType"];
                                if ([expressType isEqualToString:@"BD"]) {// 把背兜物流取出来 背兜超人运费5元起
                                    NSString *expressBaseFee = dic[@"baseFee"];
                                    goodExpressLabel.text = [NSString stringWithFormat:@"%@%.2f元起",@"背兜超人运费：",[expressBaseFee floatValue]];
                                }
                            }
                        } else {
                            for (NSDictionary *dic in expressList) {
                                NSString *expressType = dic[@"expressType"];
                                if ([expressType isEqualToString:@"REMOTE"]) {// 把三方物流取出来
                                    NSString *expressBaseFee = dic[@"baseFee"];
                                    goodExpressLabel.text = [NSString stringWithFormat:@"%@%.2f",NSLocalizedString(@"Third party Express fees", nil),[expressBaseFee floatValue]];
                                    if ([[BDAccountManagerModel shareInstance].langage isEqualToString:@"zang"]) {
                                        goodExpressLabel.text = [NSString stringWithFormat:@"%@%.2f",@"第三方物流运费：",[expressBaseFee floatValue]];
                                    }
                                }
                            }
                        }
                    }
                }
            }
            
            UILabel *goodScore = [(UILabel *)cell viewWithTag:108];
            if ([[BDAccountManagerModel shareInstance].langage isEqualToString:@"zang"]) {
                goodScore.font = [UIFont fontWithName:@"Bzdbt" size:7.0];
            }
            
            return cell;
        } else if (indexPath.row == 2) {
            static NSString *cellStr = @"goodCommentsTitleCell";
            UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:cellStr];
            
            UILabel *label = [(UILabel *)cell viewWithTag:101];
            label.text = [NSString stringWithFormat:@"%@(%lu)",NSLocalizedString(@"Commodity comments", nil),(unsigned long)_commentsList.count];
            
            return cell;
        } else {
            if (_commentsList.count > 0) {
                if ((indexPath.row == 3 && _commentsList.count == 1) ||
                    ((indexPath.row == 3 || indexPath.row == 4) && _commentsList.count == 2) ||
                    ((indexPath.row == 3 || indexPath.row == 4 || indexPath.row == 5) && _commentsList.count >= 3)) {
                    static NSString *cellStr = @"goodCommentsCell";
                    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:cellStr];
                    
                    UILabel *nameLabel = (UILabel *)[cell viewWithTag:101];
                    NSString *name = _commentsList[indexPath.row - 3][@"userName"];
                    if (![name isEqual:[NSNull null]]) {
                        nameLabel.text = name;
                    } else {
                        nameLabel.text = @"匿名";
                    }
                    NSNumber *level = _commentsList[indexPath.row - 3][@"level"];
                    if (![level isEqual:[NSNull null]]) {
                        NSInteger levelValue = [level integerValue];
                        NSInteger index = 0;
                        UIView *containerView = [cell viewWithTag:102];
                        for (UIView *view in containerView.subviews) {
                            if ([view isKindOfClass:[UIImageView class]]) {
                                UIImageView *imageView = (UIImageView *)view;
                                NSString *imageName = index < levelValue ? @"ratingbar_selected" : @"ratingbar_unselected";
                                imageView.image = [UIImage imageNamed:imageName];
                                index++;
                            }
                        }
                    }
                    
                    UILabel *dateLabel = (UILabel *)[cell viewWithTag:103];
                    NSArray *evaluationContents = _commentsList[indexPath.row - 3][@"evaluationContents"];
                    for (UIView *view in cell.contentView.subviews) {
                        if (view.tag >= 104 && view.tag <= 107) {
                            view.hidden = YES;
                        }
                    }
                    // 废弃的评论
                    if (![evaluationContents isEqual:[NSNull null]] &&
                        [evaluationContents isKindOfClass:[NSArray class]]) {
                        for (NSDictionary *dic in evaluationContents) {
                            NSString *type = [dic valueForKey:@"type"];
                            if (![type isEqual:[NSNull null]] &&
                                [type isEqualToString:@"EVALUATION"]) {
                                // 显示评论时间
                                if (![[dic valueForKey:@"time"] isEqual:[NSNull null]]) {
                                    NSTimeInterval time = [[dic valueForKey:@"time"] doubleValue] / 1000;
                                    dateLabel.text = [NSString converToDateString:time formatter:@"yyyy-MM-dd HH:mm:ss"];
                                }
                                UILabel *contentLabel = (UILabel *)[cell viewWithTag:104];
                                contentLabel.hidden = YES;
                                NSString *content = [dic valueForKey:@"content"];
                                if (![content isEqual:[NSNull null]] &&
                                    content.length > 0) {
                                    contentLabel.hidden = NO;
                                    contentLabel.text = content;
                                }
                            }
                            if (![type isEqual:[NSNull null]] &&
                                [type isEqualToString:@"APPEND"]) {
                                NSString *content = [dic valueForKey:@"content"];
                                UILabel *contentLabel = (UILabel *)[cell viewWithTag:105];
                                contentLabel.hidden = YES;
                                if (![content isEqual:[NSNull null]] &&
                                    content.length > 0) {
                                    contentLabel.hidden = NO;
                                    contentLabel.text = [NSString stringWithFormat:@"[%@]：%@",NSLocalizedString(@"Add comment", nil),content];
                                    
                                    NSMutableAttributedString * attriStr = [[NSMutableAttributedString alloc] initWithString:contentLabel.text];
                                    contentLabel.text = @"";
                                    [attriStr addAttribute:NSForegroundColorAttributeName value:RGBColor(51, 51, 51) range:NSMakeRange(0, 6)];
                                    [attriStr addAttribute:NSForegroundColorAttributeName value:RGBColor(102, 102, 102) range:NSMakeRange(6, attriStr.length - 6)];
                                    [attriStr addAttribute:NSFontAttributeName value:[UIFont systemFontOfSize:12] range:NSMakeRange(0, attriStr.length)];
                                    contentLabel.attributedText = attriStr;
                                    
                                    if ([[BDAccountManagerModel shareInstance].langage isEqualToString:@"zang"]) {
                                        contentLabel.text = [NSString stringWithFormat:@"[%@]：%@",@"追加评论",content];
                                    }
                                }
                            }
                            if (![type isEqual:[NSNull null]] &&
                                [type isEqualToString:@"EVALUATION_REPLY"]) {
                                NSString *content = [dic valueForKey:@"content"];
                                UILabel *contentLabel = (UILabel *)[cell viewWithTag:106];
                                contentLabel.hidden = YES;
                                if (![content isEqual:[NSNull null]] &&
                                    content.length > 0) {
                                    contentLabel.hidden = NO;
                                    contentLabel.text = [NSString stringWithFormat:@"[%@]：%@",NSLocalizedString(@"Seller reply", nil),content];
                                    
                                    NSMutableAttributedString * attriStr = [[NSMutableAttributedString alloc] initWithString:contentLabel.text];
                                    contentLabel.text = @"";
                                    [attriStr addAttribute:NSForegroundColorAttributeName value:RGBColor(51, 51, 51) range:NSMakeRange(0, 6)];
                                    [attriStr addAttribute:NSForegroundColorAttributeName value:RGBColor(102, 102, 102) range:NSMakeRange(6, attriStr.length - 6)];
                                    [attriStr addAttribute:NSFontAttributeName value:[UIFont systemFontOfSize:12] range:NSMakeRange(0, attriStr.length)];
                                    contentLabel.attributedText = attriStr;
                                    
                                    if ([[BDAccountManagerModel shareInstance].langage isEqualToString:@"zang"]) {
                                        contentLabel.text = [NSString stringWithFormat:@"[%@]：%@",@"商家回复",content];
                                    }
                                }
                            }
                            if (![type isEqual:[NSNull null]] &&
                                [type isEqualToString:@"APPEND_REPLY"]) {
                                NSString *content = [dic valueForKey:@"content"];
                                UILabel *contentLabel = (UILabel *)[cell viewWithTag:107];
                                contentLabel.hidden = YES;
                                if (![content isEqual:[NSNull null]] &&
                                    content.length > 0) {
                                    contentLabel.hidden = NO;
                                    contentLabel.text = [NSString stringWithFormat:@"[%@]：%@",NSLocalizedString(@"Seller reply Add comment", nil),content];
                                    
                                    NSMutableAttributedString * attriStr = [[NSMutableAttributedString alloc] initWithString:contentLabel.text];
                                    contentLabel.text = @"";
                                    [attriStr addAttribute:NSForegroundColorAttributeName value:RGBColor(51, 51, 51) range:NSMakeRange(0, 10)];
                                    [attriStr addAttribute:NSForegroundColorAttributeName value:RGBColor(102, 102, 102) range:NSMakeRange(10, attriStr.length - 10)];
                                    [attriStr addAttribute:NSFontAttributeName value:[UIFont systemFontOfSize:12] range:NSMakeRange(0, attriStr.length)];
                                    contentLabel.attributedText = attriStr;
                                    
                                    if ([[BDAccountManagerModel shareInstance].langage isEqualToString:@"zang"]) {
                                        contentLabel.text = [NSString stringWithFormat:@"[%@]：%@",@"商家回复追加评论",content];
                                    }
                                }
                            }
                        }
                    }
                    
                    return cell;
                } else {// 查看全部评价
                    static NSString *cellStr = @"goodAllCommentsCell";
                    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:cellStr];
                    
                    UIButton *allCommentsButton = (UIButton *)[cell viewWithTag:101];
                    allCommentsButton.layer.cornerRadius = 5.0;
                    allCommentsButton.layer.borderWidth = 1.0;
                    allCommentsButton.layer.borderColor = RGBColor(215, 19, 33).CGColor;
                    allCommentsButton.layer.masksToBounds = YES;
                    
                    return cell;
                }
                
            } else {
                static NSString *cellStr = @"goodNoCommentCell";
                UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:cellStr];
                
                return cell;
            }
        }
    } else if (tableView == _secondTableView) {
        if (indexPath.row == 0) {
            static NSString *cellStr = @"descCell";
            UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:cellStr];
            
            UITextView *textView = [(UITextView *)cell viewWithTag:101];
            NSString *desc = _commodityDic[@"des"];
            if (![desc isEqual:[NSNull null]]) {
                textView.text = desc;
            }
            
            return cell;
            
        } else {
            static NSString *cellStr = @"imageCell";
            UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:cellStr];
            
            if (cell.subviews.count <= 2) {
                NSInteger index = 0;
                for (NSDictionary *dic in _detailList) {
                    NSString *picUrl = dic[@"picUrl"];
                    if (![picUrl isEqual:[NSNull null]] &&
                        picUrl.length > 0) {
                        UIImageView *imageView = [[UIImageView alloc] initWithFrame:CGRectMake(5,index * (kScreen_Width - 10) + 30.0,kScreen_Width - 10,kScreen_Width - 10)];
                        NSInteger width = imageView.width;
                        NSInteger height = imageView.height;
                        picUrl = [NSString stringWithFormat:@"%@?dp_cmd=/imageView2/mode/2/w/%ld/h/%ld/",picUrl,(long)width,(long)height];
                        [imageView sd_setImageWithURL:[NSURL URLWithString:picUrl] placeholderImage:[UIImage imageNamed:@"image_empty"]];
                        imageView.tag = 200 + index;
                        [cell addSubview:imageView];
                        index++;
                    }
                }
            } else {
                NSInteger index = 0;
                for (NSDictionary *dic in _detailList) {
                    NSString *picUrl = dic[@"picUrl"];
                    if (![picUrl isEqual:[NSNull null]] &&
                        picUrl.length > 0) {
                        UIImageView *imageView = [cell viewWithTag:(200 + index)];
                        NSInteger width = imageView.width;
                        NSInteger height = imageView.height;
                        picUrl = [NSString stringWithFormat:@"%@?dp_cmd=/imageView2/mode/2/w/%ld/h/%ld/",picUrl,(long)width,(long)height];
                        [imageView sd_setImageWithURL:[NSURL URLWithString:picUrl] placeholderImage:[UIImage imageNamed:@"image_empty"]];
                        index++;
                    }
                }
            }
            
            return cell;
        }
    } else {
        if (_commentsList.count > 0) {
            static NSString *cellStr = @"goodCommentsCell";
            UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:cellStr];
            
            UILabel *nameLabel = (UILabel *)[cell viewWithTag:101];
            NSString *name = _commentsList[indexPath.row][@"userName"];
            if (![name isEqual:[NSNull null]]) {
                nameLabel.text = name;
            } else {
                nameLabel.text = @"匿名";
            }
            NSNumber *level = _commentsList[indexPath.row][@"level"];
            if (![level isEqual:[NSNull null]]) {
                NSInteger levelValue = [level integerValue];
                NSInteger index = 0;
                UIView *containerView = [cell viewWithTag:102];
                for (UIView *view in containerView.subviews) {
                    if ([view isKindOfClass:[UIImageView class]]) {
                        UIImageView *imageView = (UIImageView *)view;
                        NSString *imageName = index < levelValue ? @"ratingbar_selected" : @"ratingbar_unselected";
                        imageView.image = [UIImage imageNamed:imageName];
                        index++;
                    }
                }
            }
            
            UILabel *dateLabel = (UILabel *)[cell viewWithTag:103];
            NSArray *evaluationContents = _commentsList[indexPath.row][@"evaluationContents"];
            for (UIView *view in cell.contentView.subviews) {
                if (view.tag >= 104 && view.tag <= 107) {
                    UILabel *contentLabel = (UILabel *)view;
                    contentLabel.text = @"";
                }
            }
            if (![evaluationContents isEqual:[NSNull null]] &&
                [evaluationContents isKindOfClass:[NSArray class]]) {
                for (NSDictionary *dic in evaluationContents) {
                    NSString *type = [dic valueForKey:@"type"];
                    if (![type isEqual:[NSNull null]] &&
                        [type isEqualToString:@"EVALUATION"]) {
                        // 显示评论时间
                        if (![[dic valueForKey:@"time"] isEqual:[NSNull null]]) {
                            NSTimeInterval time = [[dic valueForKey:@"time"] doubleValue] / 1000;
                            dateLabel.text = [NSString converToDateString:time formatter:@"yyyy-MM-dd HH:mm:ss"];
                        }
                        UILabel *contentLabel = (UILabel *)[cell viewWithTag:104];
                        NSString *content = [dic valueForKey:@"content"];
                        if (![content isEqual:[NSNull null]] &&
                            content.length > 0) {
                            contentLabel.hidden = NO;
                            contentLabel.text = content;
                        }
                    }
                    if (![type isEqual:[NSNull null]] &&
                        [type isEqualToString:@"APPEND"]) {
                        NSString *content = [dic valueForKey:@"content"];
                        UILabel *contentLabel = (UILabel *)[cell viewWithTag:105];
                        if (![content isEqual:[NSNull null]] &&
                            content.length > 0) {
                            contentLabel.hidden = NO;
                            contentLabel.text = [NSString stringWithFormat:@"[%@]：%@",NSLocalizedString(@"Add comment", nil),content];
                            
                            NSMutableAttributedString * attriStr = [[NSMutableAttributedString alloc] initWithString:contentLabel.text];
                            contentLabel.text = @"";
                            [attriStr addAttribute:NSForegroundColorAttributeName value:RGBColor(51, 51, 51) range:NSMakeRange(0, 6)];
                            [attriStr addAttribute:NSForegroundColorAttributeName value:RGBColor(102, 102, 102) range:NSMakeRange(6, attriStr.length - 6)];
                            [attriStr addAttribute:NSFontAttributeName value:[UIFont systemFontOfSize:12] range:NSMakeRange(0, attriStr.length)];
                            contentLabel.attributedText = attriStr;
                            
                            if ([[BDAccountManagerModel shareInstance].langage isEqualToString:@"zang"]) {
                                contentLabel.text = [NSString stringWithFormat:@"[%@]：%@",@"追加评论",content];
                            }
                        }
                    }
                    if (![type isEqual:[NSNull null]] &&
                        [type isEqualToString:@"EVALUATION_REPLY"]) {
                        NSString *content = [dic valueForKey:@"content"];
                        UILabel *contentLabel = (UILabel *)[cell viewWithTag:106];
                        if (![content isEqual:[NSNull null]] &&
                            content.length > 0) {
                            contentLabel.hidden = NO;
                            contentLabel.text = [NSString stringWithFormat:@"[%@]：%@",NSLocalizedString(@"Seller reply", nil),content];
                            
                            NSMutableAttributedString * attriStr = [[NSMutableAttributedString alloc] initWithString:contentLabel.text];
                            contentLabel.text = @"";
                            [attriStr addAttribute:NSForegroundColorAttributeName value:RGBColor(51, 51, 51) range:NSMakeRange(0, 6)];
                            [attriStr addAttribute:NSForegroundColorAttributeName value:RGBColor(102, 102, 102) range:NSMakeRange(6, attriStr.length - 6)];
                            [attriStr addAttribute:NSFontAttributeName value:[UIFont systemFontOfSize:12] range:NSMakeRange(0, attriStr.length)];
                            contentLabel.attributedText = attriStr;
                            
                            if ([[BDAccountManagerModel shareInstance].langage isEqualToString:@"zang"]) {
                                contentLabel.text = [NSString stringWithFormat:@"[%@]：%@",@"商家回复",content];
                            }
                        }
                    }
                    if (![type isEqual:[NSNull null]] &&
                        [type isEqualToString:@"APPEND_REPLY"]) {
                        NSString *content = [dic valueForKey:@"content"];
                        UILabel *contentLabel = (UILabel *)[cell viewWithTag:107];
                        if (![content isEqual:[NSNull null]] &&
                            content.length > 0) {
                            contentLabel.hidden = NO;
                            contentLabel.text = [NSString stringWithFormat:@"[%@]：%@",NSLocalizedString(@"Seller reply Add comment", nil),content];
                            
                            NSMutableAttributedString * attriStr = [[NSMutableAttributedString alloc] initWithString:contentLabel.text];
                            contentLabel.text = @"";
                            [attriStr addAttribute:NSForegroundColorAttributeName value:RGBColor(51, 51, 51) range:NSMakeRange(0, 10)];
                            [attriStr addAttribute:NSForegroundColorAttributeName value:RGBColor(102, 102, 102) range:NSMakeRange(10, attriStr.length - 10)];
                            [attriStr addAttribute:NSFontAttributeName value:[UIFont systemFontOfSize:12] range:NSMakeRange(0, attriStr.length)];
                            contentLabel.attributedText = attriStr;
                            
                            if ([[BDAccountManagerModel shareInstance].langage isEqualToString:@"zang"]) {
                                contentLabel.text = [NSString stringWithFormat:@"[%@]：%@",@"商家回复追加评论",content];
                            }
                        }
                    }
                }
            }
            
            return cell;
        } else {
            static NSString *cellStr = @"goodNoCommentCell";
            UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:cellStr];
            
            return cell;
        }
    }
}

#pragma mark tableView delegate

- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath {
    if (tableView == _tableView) {
        if (indexPath.row == 0) {
            return kScreen_Width / firstHeightWidthRatio;
        } else if (indexPath.row == 1) {
            return 100.0;
        } else if (indexPath.row == 2) {
            return 26.0;
        } else {
            if (_commentsList.count == 0) {
                return 127.0;
            } else {
                if ((indexPath.row == 3 && _commentsList.count == 1) ||
                    ((indexPath.row == 3 || indexPath.row == 4) && _commentsList.count == 2) ||
                    ((indexPath.row == 3 || indexPath.row == 4 || indexPath.row == 5) && _commentsList.count >= 3)) {
                    NSString *evaluation;
                    NSString *append;
                    NSString *evaluation_reply;
                    NSString *append_reply;
                    NSArray *evaluationContents = _commentsList[indexPath.row - 3][@"evaluationContents"];
                    if (![evaluationContents isEqual:[NSNull null]] &&
                        [evaluationContents isKindOfClass:[NSArray class]]) {
                        for (NSDictionary *dic in evaluationContents) {
                            NSString *type = [dic valueForKey:@"type"];
                            if (![type isEqual:[NSNull null]] &&
                                [type isEqualToString:@"EVALUATION"]) {
                                evaluation = [dic valueForKey:@"content"];
                            }
                            if (![type isEqual:[NSNull null]] &&
                                [type isEqualToString:@"APPEND"]) {
                                append = [NSString stringWithFormat:@"[%@]：%@",NSLocalizedString(@"Add comment", nil),[dic valueForKey:@"content"]];
                            }
                            if (![type isEqual:[NSNull null]] &&
                                [type isEqualToString:@"EVALUATION_REPLY"]) {
                                evaluation_reply = [dic valueForKey:@"content"];
                                evaluation_reply = [NSString stringWithFormat:@"[%@]：%@",NSLocalizedString(@"Seller reply", nil),[dic valueForKey:@"content"]];
                            }
                            if (![type isEqual:[NSNull null]] &&
                                [type isEqualToString:@"APPEND_REPLY"]) {
                                append_reply = [dic valueForKey:@"content"];
                                append_reply = [NSString stringWithFormat:@"[%@]：%@",NSLocalizedString(@"Seller reply Add comment", nil),[dic valueForKey:@"content"]];
                            }
                        }
                        // 这是第一页老的评论，现在只显示第一条了
                        CGFloat cellHeight = 0;
                        if (![evaluation isEqual:[NSNull null]] && evaluation.length > 0) {
                            CGFloat height = [evaluation boundingHeightWithSize:CGSizeMake(kScreen_Width - 16.0, CGFLOAT_MAX) font:[UIFont systemFontOfSize:12.0] lineSpace:12.0] + 12.0;
                            cellHeight +=  height;
                        }
                        if (![append isEqual:[NSNull null]] && append.length > 0) {
                            CGFloat height = [append boundingHeightWithSize:CGSizeMake(kScreen_Width - 16.0, CGFLOAT_MAX) font:[UIFont systemFontOfSize:12.0] lineSpace:12.0];
                            cellHeight +=  height;
                            cellHeight -= 10.0;
                        }
                        if (![evaluation_reply isEqual:[NSNull null]] && evaluation_reply.length > 0) {
                            CGFloat height = [evaluation_reply boundingHeightWithSize:CGSizeMake(kScreen_Width - 16.0, CGFLOAT_MAX) font:[UIFont systemFontOfSize:13.0] lineSpace:12.0];
                            cellHeight +=  height;
                            cellHeight -= 10.0;
                        }
                        if (![append_reply isEqual:[NSNull null]] && append_reply.length > 0) {
                            CGFloat height = [append_reply boundingHeightWithSize:CGSizeMake(kScreen_Width - 16.0, CGFLOAT_MAX) font:[UIFont systemFontOfSize:13.0] lineSpace:12.0];
                            cellHeight +=  height;
                            cellHeight -= 0.0;
                        }
                        return cellHeight + 39.0;
                    }
                } else {
                    return 44.0;
                }
            }
        }
    } else if (tableView == _secondTableView) {
        if (indexPath.row == 0) {
            NSString *desc = _commodityDic[@"des"];
            NSArray *array = [desc componentsSeparatedByString:@"\n"];
            NSInteger count = [array count] - 1;
            CGFloat cellHeight = 60.0;
            if (![desc isEqual:[NSNull null]]) {
                cellHeight = [desc boundingHeightWithSize:CGSizeMake(kScreen_Width - 16.0, CGFLOAT_MAX) font:[UIFont systemFontOfSize:14.0] lineSpace:5.0] + 60.0;
                cellHeight = cellHeight < 80 ? 80 : cellHeight;
            }
            NSLog(@"count is %ld",(long)count);
            return cellHeight - count * 12;
        } else if (indexPath.row == 1) {
            if (_detailList.count > 0) {
                return _detailList.count * (kScreen_Width - 10) + 30.0;
            }
            return 100;
        }
    } else {
        if (_commentsList.count == 0) {
            _thirdTableView.scrollEnabled = NO;
            return kScreen_Height - 104.0;
        } else {
            _thirdTableView.scrollEnabled = YES;
            NSString *evaluation;
            NSString *append;
            NSString *evaluation_reply;
            NSString *append_reply;
            NSArray *evaluationContents = _commentsList[indexPath.row][@"evaluationContents"];
            if (![evaluationContents isEqual:[NSNull null]] &&
                [evaluationContents isKindOfClass:[NSArray class]]) {
                for (NSDictionary *dic in evaluationContents) {
                    NSString *type = [dic valueForKey:@"type"];
                    if (![type isEqual:[NSNull null]] &&
                        [type isEqualToString:@"EVALUATION"]) {
                        evaluation = [dic valueForKey:@"content"];
                    }
                    if (![type isEqual:[NSNull null]] &&
                        [type isEqualToString:@"APPEND"]) {
                        append = [NSString stringWithFormat:@"[%@]：%@",NSLocalizedString(@"Add comment", nil),[dic valueForKey:@"content"]];
                    }
                    if (![type isEqual:[NSNull null]] &&
                        [type isEqualToString:@"EVALUATION_REPLY"]) {
                        evaluation_reply = [dic valueForKey:@"content"];
                        evaluation_reply = [NSString stringWithFormat:@"[%@]：%@",NSLocalizedString(@"Seller reply", nil),[dic valueForKey:@"content"]];
                    }
                    if (![type isEqual:[NSNull null]] &&
                        [type isEqualToString:@"APPEND_REPLY"]) {
                        append_reply = [dic valueForKey:@"content"];
                        append_reply = [NSString stringWithFormat:@"[%@]：%@",NSLocalizedString(@"Seller reply Add comment", nil),[dic valueForKey:@"content"]];
                    }
                }
                CGFloat cellHeight = 0;
                if (![evaluation isEqual:[NSNull null]] && evaluation.length > 0) {
                    CGFloat height = [evaluation boundingHeightWithSize:CGSizeMake(kScreen_Width - 16.0, CGFLOAT_MAX) font:[UIFont systemFontOfSize:13.0] lineSpace:12.0] + 8.0;
                    cellHeight +=  height;
                }
                if (![append isEqual:[NSNull null]] && append.length > 0) {
                    CGFloat height = [append boundingHeightWithSize:CGSizeMake(kScreen_Width - 16.0, CGFLOAT_MAX) font:[UIFont systemFontOfSize:13.0] lineSpace:12.0];
                    cellHeight +=  height;
                    cellHeight -= 10.0;
                }
                if (![evaluation_reply isEqual:[NSNull null]] && evaluation_reply.length > 0) {
                    CGFloat height = [evaluation_reply boundingHeightWithSize:CGSizeMake(kScreen_Width - 16.0, CGFLOAT_MAX) font:[UIFont systemFontOfSize:13.0] lineSpace:12.0];
                    cellHeight +=  height;
                    cellHeight -= 10.0;
                }
                if (![append_reply isEqual:[NSNull null]] && append_reply.length > 0) {
                    CGFloat height = [append_reply boundingHeightWithSize:CGSizeMake(kScreen_Width - 16.0, CGFLOAT_MAX) font:[UIFont systemFontOfSize:13.0] lineSpace:12.0];
                    cellHeight +=  height;
                    cellHeight -= 5.0;
                }
                return cellHeight + 39.0 + 40.0;
            }
        }
    }
    return 0.0;
}

#pragma mark - UIScrollViewDelegate

- (void)scrollViewDidScroll:(UIScrollView *)scrollView {
    if (scrollView == self.tableView || scrollView == self.secondTableView || scrollView == self.thirdTableView) {
        // 滑动到底部时显示返回顶部按钮
        CGFloat offsetY = scrollView.contentOffset.y;
        if (offsetY > 100 && !_showTop) {
            _showTop = YES;
            [UIView animateWithDuration:0.3 animations:^{
                _topButton.y = kScreen_Height - 95.0;
                if (self.notCustomNavigatonBar) {
                    _topButton.y -= 64.0;
                }
            } completion:^(BOOL finished) {
                
            }];
        }
        if (offsetY < 100 && _showTop){
            _showTop = NO;
            [UIView animateWithDuration:0.3 animations:^{
                _topButton.y = kScreen_Height;
                if (self.notCustomNavigatonBar) {
                    _topButton.y -= 64.0;
                }
            } completion:^(BOOL finished) {
            }];
        }
    }
    
    if (scrollView == self.tableView) {
        SDCycleScrollView *cycleScrollView = (SDCycleScrollView *)[self.containerView viewWithTag:101];
        if (scrollView.contentOffset.y < 0) {// 下拉改变顶部滑动图片缩放
            float diff = -scrollView.contentOffset.y;
            float oldH = _defaultTopViewRect.size.height;
            float oldW = _defaultTopViewRect.size.width;
            [cycleScrollView setFrame:CGRectMake(0, diff * 0.7, oldW, oldH)];
        } else {
            float diff = scrollView.contentOffset.y;
            [cycleScrollView setY:-diff * 0.5];
        }
    }
}

- (void)scrollViewDidEndDecelerating:(UIScrollView *)scrollView {
    if (scrollView == self.containerScrollView) {
        //获取当前视图的宽度
        CGFloat pageWith = scrollView.frame.size.width;
        //根据scrolView的左右滑动,对pageCotrol的当前指示器进行切换(设置currentPage)
        int page = floor((scrollView.contentOffset.x - pageWith / 2) /pageWith) + 1;
        if (page == 0) {
            [self goodMethod];
        } else if (page == 1)  {
            [self detailMethod];
        } else if (page == 2)  {
            [self commentMethod];
        }
    }
}

#pragma mark - SDCycleScrollViewDelegate

- (void)cycleScrollView:(SDCycleScrollView *)cycleScrollView didSelectItemAtIndex:(NSInteger)index {
    NSLog(@"index = %ld",(long)index);
}

#pragma mark - standardView  delegate

-(StandardsView *)buildStandardView:(UIImage *)img andIndex:(NSInteger)index {// 构造加入购物车和立即购买时的弹出界面
    _standview = [[StandardsView alloc] init];
    _standview.tag = index;
    _standview.delegate = self;
    // 商品图片
    NSInteger width = _standview.mainImgView.width;
    NSInteger height = _standview.mainImgView.height;
    NSString *icon = _commodityDic[@"icon"];
    NSString *goodImageUrl = nil;
    if (![icon isEqual:[NSNull null]]) {
        goodImageUrl = [NSString stringWithFormat:@"%@?dp_cmd=/imageView2/mode/2/w/%ld/h/%ld/",icon,(long)width,(long)height];
    }
    [_standview.mainImgView sd_setImageWithURL:[NSURL URLWithString:goodImageUrl] placeholderImage:[UIImage imageNamed:@"image_empty"]];
    _standview.mainImgView.backgroundColor = [UIColor whiteColor];
    // 商品价格
    NSString *goodDiscount = _commodityDic[@"commodityPrice"][@"discount"];
    NSString *goodPrice = _commodityDic[@"commodityPrice"][@"price"];
    if (![goodDiscount isEqual:[NSNull null]] &&
        ![goodPrice isEqual:[NSNull null]]) {
        // 折扣
        CGFloat discount = [goodDiscount floatValue];
        CGFloat price = [goodPrice floatValue];
        _standview.priceLab.text = [NSString stringWithFormat:@"¥ %.2f",price * discount];
        _standview.priceLab.textColor = RGBColor(254, 77, 13);
    } else {
        _standview.priceLab.text = @"未能获取价格";
    }
    //    standview.tipLab.text = @"请选择规格";
    _standview.tipLab.hidden = YES;
    // 商品库存
    NSString *num = _commodityDic[@"num"];
    if (![num isEqual:[NSNull null]]) {
        _standview.goodNum.text = [NSString stringWithFormat:@"%@%ld",NSLocalizedString(@"Stock", nil),(long)[num integerValue]];
        if ([[BDAccountManagerModel shareInstance].langage isEqualToString:@"zang"]) {
            _standview.goodNum.font = [UIFont fontWithName:@"Bzdbt" size:12.0];
        }
    } else {
        _standview.goodNum.text = @"库存获取失败";
    }
    // 确定按钮
    _standview.customBtns = @[NSLocalizedString(@"Confirm", nil)];
    // 键盘添加取消 完成按钮
    UIView *keyBoardTopView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, self.view.frame.size.width, 44)];
    keyBoardTopView.backgroundColor = [UIColor lightGrayColor];
    UIButton *btn = [[UIButton alloc] initWithFrame:CGRectMake(12, 4, 60, 36)];
    [btn setTitle:NSLocalizedString(@"Cancel", nil) forState:UIControlStateNormal];
    [btn addTarget:self action:@selector(onKeyBoardCancel:) forControlEvents:UIControlEventTouchUpInside];
    if ([[BDAccountManagerModel shareInstance].langage isEqualToString:@"zang"]) {
        btn.titleLabel.font = [UIFont fontWithName:@"Bzdbt" size:9.0];
    }
    [keyBoardTopView addSubview:btn];
    
    UIButton *btn2 = [[UIButton alloc] initWithFrame:CGRectMake(keyBoardTopView.bounds.size.width - 60 - 12, 4, 60, 36)];
    [btn2 setTitle:NSLocalizedString(@"Done", nil) forState:UIControlStateNormal];
    [btn2 setTitleColor:RGBColor(159, 27, 27) forState:UIControlStateNormal];
    [btn2 addTarget:self action:@selector(onKeyBoardFinsh:) forControlEvents:UIControlEventTouchUpInside];
    if ([[BDAccountManagerModel shareInstance].langage isEqualToString:@"zang"]) {
        btn2.titleLabel.font = [UIFont fontWithName:@"Bzdbt" size:9.0];
    }
    [keyBoardTopView addSubview:btn2];
    _standview.numberTextFied.inputAccessoryView = keyBoardTopView;
    
    //    standardClassInfo *tempClassInfo1 = [standardClassInfo StandardClassInfoWith:@"100" andStandClassName:@"红色"];
    //    standardClassInfo *tempClassInfo2 = [standardClassInfo StandardClassInfoWith:@"101" andStandClassName:@"蓝色"];
    //    NSArray *tempClassInfoArr = @[tempClassInfo1,tempClassInfo2];
    //    StandardModel *tempModel = [StandardModel StandardModelWith:tempClassInfoArr andStandName:@"颜色"];
    //
    //
    //
    //    standardClassInfo *tempClassInfo3 = [standardClassInfo StandardClassInfoWith:@"102" andStandClassName:@"XL"];
    //    standardClassInfo *tempClassInfo4 = [standardClassInfo StandardClassInfoWith:@"103" andStandClassName:@"XXL"];
    //    standardClassInfo *tempClassInfo5 = [standardClassInfo StandardClassInfoWith:@"104" andStandClassName:@"XXXXXXXXXXXXXL"];
    //    NSArray *tempClassInfoArr2 = @[tempClassInfo3,tempClassInfo4,tempClassInfo5];
    //    StandardModel *tempModel2 = [StandardModel StandardModelWith:tempClassInfoArr2 andStandName:@"尺寸"];
    //    standview.standardArr = @[tempModel,tempModel2];
    _standview.standardArr = @[];
    
    return _standview;
}

- (void)onKeyBoardCancel:(UIButton *) sender {// 键盘取消
    NSUInteger num = [_standview.numberTextFied.text integerValue];
    if (num <= 0) {
        _standview.numberTextFied.text = @"1";
    }
    [_standview endEditing:YES];
}

- (void)onKeyBoardFinsh:(UIButton *) sender {// 键盘完成
    NSUInteger num = [_standview.numberTextFied.text integerValue];
    if (num <= 0) {
        _standview.numberTextFied.text = @"1";
    }
    [_standview endEditing:YES];
}

//点击确定
-(void)StandardsView:(StandardsView *)standardView CustomBtnClickAction:(UIButton *)sender {
    if ([BDAccountManagerModel shareInstance].login) {
        // 商品库存
        NSString *num = _commodityDic[@"num"];
        NSInteger repertoryNum = [num integerValue];
        // 选择的数量大于商品库存
        if ([_standview.numberTextFied.text integerValue] > repertoryNum ||
            repertoryNum == 0) {
            [MBProgressHUD showToast:self.view withText:NSLocalizedString(@"Number is greater than the stock", nil) withOffsetY:-50];
        } else {
            if (_toCartFlag && sender.enabled) {// 加入到购物车
                //将商品图片抛到指定点
                [standardView ThrowGoodTo:CGPointMake(200, 100) andDuration:1.6 andHeight:150 andScale:20];
                [self addCart:sender];
            } else { // 立即购买
                [standardView dismiss];
                BOOL flag = NO;
                // 非便民地区 便民商品不可支付
                NSDictionary *classify = _commodityDic[@"classify"];
                if (![classify isEqual:[NSNull null]] &&
                    [classify isKindOfClass:[NSDictionary class]]) {
                    NSString *firstLevel = classify[@"firstLevel"];
                    if (![firstLevel isEqual:[NSNull null]]) {
                        if ([firstLevel isEqualToString:@"conveniency"]) {
                            flag = YES;
                            if (![[BDAccountManagerModel shareInstance].inBoundary isEqualToString:@"yes"]) {
                                if ([[BDAccountManagerModel shareInstance].inBoundary isEqualToString:@"no"]) {
                                    [MBProgressHUD showToast:self.view withText:NSLocalizedString(@"convenience good can only be purchased in the designated area", nil)];
                                } else {
                                    [MBProgressHUD showToast:self.view withText:@"正在定位，请等待"];
                                }
                                return;
                            }
                        }
                    }
                }
                
                NSString *storeName = _commodityDic[@"store"][@"name"];
                NSString *storeId = _commodityDic[@"store"][@"storeId"];
                NSString *icon = _commodityDic[@"icon"];
                NSString *name = _commodityDic[@"name"];
                NSString *goodDiscount = _commodityDic[@"commodityPrice"][@"discount"];
                NSString *goodPrice = _commodityDic[@"commodityPrice"][@"price"];
                CGFloat discount = [goodDiscount floatValue];
                CGFloat price = [goodPrice floatValue];
                NSString *commodityId = self.commodityId;
                
                
                NSUInteger goodNum = [_standview.numberTextFied.text integerValue];
                CGFloat actualPrice = discount * price;
                NSNumberFormatter *numberFormatter = [[NSNumberFormatter alloc] init];
                [numberFormatter setPositiveFormat:@"0.00"];
                NSString *temp = [numberFormatter stringFromNumber:[NSNumber numberWithFloat:actualPrice]];
                CGFloat totalPrice = [temp floatValue];
                
                NSDictionary *dic = @{@"commodityId" : commodityId,
                                      @"num" : @(goodNum),
                                      @"storeName" : storeName,
                                      @"storeId" : storeId,
                                      @"couponId" : [NSNull null],
                                      @"icon" : icon,
                                      @"name" : name,
                                      @"price" : @(totalPrice)};
                
                NSMutableDictionary *resultDic = [NSMutableDictionary dictionaryWithDictionary:dic];
                
                NSArray *payList = @[@[resultDic]];
                
                UIStoryboard *stroyboard = [UIStoryboard storyboardWithName:@"SecondStoryboard" bundle:[NSBundle mainBundle]];
                BDNavigationController *nav_vc = [stroyboard instantiateViewControllerWithIdentifier:@"navPayStoryboardID"];
                BDBeidouPayViewController *vc = (BDBeidouPayViewController *)nav_vc.topViewController;
                vc.payList = payList;
                vc.isConveniency = flag;// 是否是便民商品
                [self presentViewController:nav_vc animated:YES completion:nil];
            }
        }
    } else {// 未登录
        UIStoryboard *stroyboard = [UIStoryboard storyboardWithName:@"Main" bundle:[NSBundle mainBundle]];
        BDNavigationController *nav_vc = [stroyboard instantiateViewControllerWithIdentifier:@"navLoginStoryboardID"];
        [self presentViewController:nav_vc animated:YES completion:nil];
    }
    
}

// 点击规格代理
-(void)Standards:(StandardsView *)standardView SelectBtnClick:(UIButton *)sender andSelectID:(NSString *)selectID andStandName:(NSString *)standName andIndex:(NSInteger)index {
    NSLog(@"selectID = %@ standName = %@ index = %ld",selectID,standName,(long)index);
}

//设置确定按钮样式
-(void)StandardsView:(StandardsView *)standardView SetBtn:(UIButton *)btn {
    if (btn.tag == 0) {
        btn.backgroundColor = RGBColor(195, 3, 3);
    }
}

- (void)dismissMethod {
    dispatch_async(dispatch_get_main_queue(), ^{
        // 返回顶部按钮
        _topButton = [UIButton buttonWithType:UIButtonTypeCustom];
        _topButton.frame = CGRectMake(kScreen_Width - 45.0, 0, 40.0, 40.0);
        _topButton.y = _showTop ? kScreen_Height - 95.0 : kScreen_Height;
        if (self.notCustomNavigatonBar) {
            _topButton.y -= 64.0;
        }
        [_topButton setImage:[UIImage imageNamed:@"toTop"] forState:UIControlStateNormal];
        [_topButton addTarget:self action:@selector(scrollViewTop:) forControlEvents:UIControlEventTouchUpInside];
        [self.view addSubview:_topButton];
        [self.view bringSubviewToFront:self.bottomView];
    });
}

- (void)addCart:(UIButton *)sender {
    sender.enabled = NO;
    _standview.userInteractionEnabled = NO;
    NSString *comID = _commodityDic[@"commodityId"];
    if (![comID isEqual:[NSNull null]] && comID.length > 0) {
        NSUInteger goodNum = [_standview.numberTextFied.text integerValue];
        
        MBProgressHUD *hud = [MBProgressHUD showHUDAddedTo:self.view withText:@""];
        NSDictionary *parameters = @{@"userId":[BDAccountManagerModel shareInstance].userId,
                                     @"commodityIds":@[comID],
                                     @"num":@(goodNum)};
        
        NSString *url = [NSString stringWithFormat:@"%@%@",[BDNetworking shareInstance].baseUrl,Cart];
        [[BDNetworking shareInstance] postWithUrl:url sid:nil method:@"PUT" parameters:parameters completionHandler:^(NSObject *results, NSError *error) {
            dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(1.0 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
                sender.enabled = YES;
                _standview.userInteractionEnabled = NO;
                [_standview dismiss];
            });
            if (error != nil) {
                NSLog(@"加入购物车失败:%@",error);
                if ([[error localizedDescription] isEqualToString:@"登录超时"] && error.code == 401) {
                    hud.labelText = NSLocalizedString(@"Login timeout", nil);
                    [hud hideAfterDelay:0.5];
                    // 清除webViw cookie
                    NSHTTPCookie *cookie;
                    NSHTTPCookieStorage *storage = [NSHTTPCookieStorage sharedHTTPCookieStorage];
                    for (cookie in [storage cookies]) {
                        [storage deleteCookie:cookie];
                    }
                    [BDAccountManagerModel shareInstance].authorization = @"";
                    [BDAccountManagerModel shareInstance].login = NO;
                    UIStoryboard *stroyboard = [UIStoryboard storyboardWithName:@"Main" bundle:[NSBundle mainBundle]];
                    BDNavigationController *nav_addrVc = [stroyboard instantiateViewControllerWithIdentifier:@"navLoginStoryboardID"];
                    [self presentViewController:nav_addrVc animated:YES completion:nil];
                } else {
                    hud.labelText = @"加入购物车失败";
                    [hud hideAfterDelay:0.5];
                }
            } else {
                [hud hideAfterDelay:0.5];
                NSLog(@"result = %@",results);
            }
        }];
    }
}

#pragma mark - IBActions

- (IBAction)addBeidouButtonPressed:(UIButton *)sender {
    [_topButton removeFromSuperview];
    
    if (![BDAccountManagerModel shareInstance].login) {
        UIStoryboard *stroyboard = [UIStoryboard storyboardWithName:@"Main" bundle:[NSBundle mainBundle]];
        BDNavigationController *nav_addrVc = [stroyboard instantiateViewControllerWithIdentifier:@"navLoginStoryboardID"];
        [self presentViewController:nav_addrVc animated:YES completion:nil];
    } else {
        _toCartFlag = YES;
        
        StandardsView *mystandardsView = [self buildStandardView:sender.imageView.image andIndex:sender.tag];
        mystandardsView.GoodDetailView = self.view;//设置该属性 对应的view 会缩小
        mystandardsView.showAnimationType = StandsViewShowAnimationShowFrombelow;
        mystandardsView.dismissAnimationType = StandsViewDismissAnimationDisFrombelow;
        [mystandardsView show];
    }
}

- (IBAction)payButtonPressed:(UIButton *)sender {
    [_topButton removeFromSuperview];

    if (![BDAccountManagerModel shareInstance].login) {
        UIStoryboard *stroyboard = [UIStoryboard storyboardWithName:@"Main" bundle:[NSBundle mainBundle]];
        BDNavigationController *nav_addrVc = [stroyboard instantiateViewControllerWithIdentifier:@"navLoginStoryboardID"];
        [self presentViewController:nav_addrVc animated:YES completion:nil];
    } else {
        _toCartFlag = NO;
        
        StandardsView *mystandardsView = [self buildStandardView:sender.imageView.image andIndex:sender.tag];
        mystandardsView.GoodDetailView = self.view;//设置该属性 对应的view 会缩小
        mystandardsView.showAnimationType = StandsViewShowAnimationShowFrombelow;
        mystandardsView.dismissAnimationType = StandsViewDismissAnimationDisFrombelow;
        [mystandardsView show];
    }
}

- (IBAction)allCommentsButton:(UIButton *)sender {
    [self commentMethod];
}


/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
